﻿package plugin.juezhan.ui
{
    import com.core.*;
    import com.greensock.*;
    import com.greensock.easing.*;
    import flash.events.*;
    import flash.geom.*;
    import manager.*;
    import plugin.juezhan.*;
    import plugin.juezhan.controller.*;
    import uiresource.juezhan.*;

    public class JueZhanUIControl extends juezhanUI
    {
        private var mUIBase:JueZhan;
        private var mTianGuanControl:JueZhanTianGuanControl;
        private var rankrewp:Point;
        private var zhanshiboxp:Point;

        public function JueZhanUIControl(param1:JueZhan)
        {
            this.rankrewp = new Point();
            this.zhanshiboxp = new Point();
            this.mUIBase = param1;
            return;
        }// end function

        override protected function createChildren() : void
        {
            viewClassMap["uiresource.juezhan.SanviewUI"] = RankRewardCtrl;
            viewClassMap["uiresource.juezhan.ZhanshiUI"] = ZhanshiCtrl;
            loadUI("juezhan.xml");
            return;
        }// end function

        override protected function initializeView() : void
        {
            super.initializeView();
            this.listener();
            this.mTianGuanControl = new JueZhanTianGuanControl(this);
            var _loc_1:* = Control.create(JueZhanControl, this);
            ModelProxy.addObserver("juezhan", _loc_1);
            return;
        }// end function

        public function openRefresh(param1:Object) : void
        {
            if (this.mTianGuanControl)
            {
                this.mTianGuanControl.update();
            }
            this.mTianGuanControl.showModel();
            return;
        }// end function

        public function tianguanProgress(param1:Array) : void
        {
            if (this.mTianGuanControl)
            {
                this.mTianGuanControl.updateProgress(param1);
            }
            return;
        }// end function

        public function tgRankInit(param1:Object) : void
        {
            this.mTianGuanControl.rankInit(param1);
            return;
        }// end function

        public function restgrewards(param1:int) : void
        {
            this.mTianGuanControl.restgrewards(param1);
            return;
        }// end function

        private function listener() : void
        {
            btnClose.addEventListener(MouseEvent.CLICK, this.closeWindowHandler);
            rankLinkBtn.addEventListener(MouseEvent.CLICK, this.rankLinkBtnClickHandler);
            closerank.addEventListener(MouseEvent.CLICK, this.closerankHandler);
            lqlabel.addEventListener(MouseEvent.CLICK, this.lqlabelHandler);
            rankrew.closeBtn.addEventListener(MouseEvent.CLICK, this.closeHandler);
            linkrank.addEventListener(MouseEvent.CLICK, this.linkrankHandler);
            this.rankrewp.x = rankbox.x;
            this.rankrewp.y = rankbox.y;
            this.zhanshiboxp.x = zhanshibox.x;
            zhanshibox.y = zhanshibox.y;
            return;
        }// end function

        protected function lqlabelHandler(event:MouseEvent) : void
        {
            rankrew.visible = true;
            return;
        }// end function

        protected function closeHandler(event:MouseEvent) : void
        {
            rankrew.visible = false;
            return;
        }// end function

        protected function closerankHandler(event:MouseEvent) : void
        {
            rankbox.visible = false;
            return;
        }// end function

        protected function linkrankHandler(event:MouseEvent) : void
        {
            if (this.zhanshibox.visible)
            {
                (zhanshibox as ZhanshiCtrl).clear();
            }
            else
            {
                this.rankbox.visible = false;
                (zhanshibox as ZhanshiCtrl).open();
                zhanshibox.x = this.zhanshiboxp.x - zhanshibox.width;
                zhanshibox.alpha = 0;
                TweenLite.to(zhanshibox, 0.8, {x:this.zhanshiboxp.x, alpha:1, ease:Circ.easeOut});
            }
            return;
        }// end function

        protected function rankLinkBtnClickHandler(event:MouseEvent) : void
        {
            if (this.rankbox.visible)
            {
                rankbox.visible = false;
            }
            else
            {
                zhanshibox.visible = false;
                rankbox.visible = true;
                rankbox.x = this.rankrewp.x - rankbox.width;
                rankbox.alpha = 0;
                TweenLite.to(rankbox, 0.8, {x:this.rankrewp.x, alpha:1, ease:Circ.easeOut});
            }
            return;
        }// end function

        public function restgrankrewards() : void
        {
            this.mTianGuanControl.mRankControl.getRankReward();
            return;
        }// end function

        private function closeWindowHandler(event:MouseEvent) : void
        {
            this.close();
            return;
        }// end function

        public function close() : void
        {
            this.mTianGuanControl.clearModel();
            this.mUIBase.close();
            return;
        }// end function

        public function get groupID() : int
        {
            return PluginManager.instance.getGroupId("juezhan");
        }// end function

    }
}
